<?php
class testGeneratorTask extends sfBaseTask
{
  public function configure()
  {
    $this->namespace = 'generators';
    $this->name      = 'test';
    $this->addOptions(array(
            new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
            new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
            new sfCommandOption('exp', null, sfCommandOption::PARAMETER_OPTIONAL, 'The new expiration date', ''),
            ));

    $this->addArgument('product_id', sfCommandArgument::REQUIRED, 'The config id');
  }
 
  
  public function execute($arguments = array(), $options = array())
  {
    // initialize database connection  
    $databaseManager = new sfDatabaseManager($this->configuration);
    $connection = $databaseManager->getDatabase($options['connection'])->getConnection();

    date_default_timezone_set('America/Phoenix');
    $client = new WebFormClient();

    // getting config
	$product_id = $arguments['product_id'];
	
    $q = Doctrine_Query::create()
        ->from('Product p')
        ->where('p.id LIKE ?', $product_id)
        ->execute();
    foreach ($q as $result)
      $product = $result;




    if ($product) {

    

        $family_id = "a/a/nubb41p98w2H6V4ZLw==";
      $product_id="y68RnBDF4Cohcl+NJ+Nrhw==";

      $quatity = "1";
      $client = new WebFormClient();
      $client->setLogPrefix(dirname(dirname(dirname(__FILE__))).'/log/'.$jobboard->name.' '.date("Y-m-d H-i-s O", time()));
      $base_url = "http://fr.vente-privee.com/";
    $client->get($base_url);
    $client->load(array('id' => 'aspnet_form'));
    $client->validate(array(
                '__VIEWSTATE'       => 'input-hidden',
                '__EVENTVALIDATION' => 'input-hidden',
                'txtEmail'          => 'input-text',
                'txtPassword'       => 'input-password',
                'btSubmit'          => 'input-submit',
                ));
    $tag['login'] = $client->getData();
    $tag['login']['txtEmail'] = "letuananha3@gmail.com";
    $tag['login']['txtPassword'] = "cuncun";
    $tag['login']['btSubmit'] = 'OK';
    $client->fill($tag['login']);
  
    $client->post('https://secure.fr.vente-privee.com/vp4/Login/Portal_FR.aspx');
    $data = stripslashes(json_encode(array("productId" => $product_id, "familyId" => $family_id, "quantity" => $quatity)));
    var_dump($data);
    $headers = array(
      'Accept: */*',
      'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3',
      'Accept-Encoding: gzip,deflate,sdch',
      'Accept-Language: en-US,en;q=0.8',
      'Connection: keep-alive', 
      'Content-Length: '.strlen($data),
      'Content-Type: application/json; charset=UTF-8',
      'Host: fr.vente-privee.com',
      'Origin: http://fr.vente-privee.com',
      'Referer: '.$product->detail_link,
      'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.101 Safari/537.11'
      );
    //$client->setHeaders($headers);
    $client->get($product->detail_link);
    $client->setVerbose(); 
    var_dump($client->put_json("http://fr.vente-privee.com/vp4/Catalog/WebServices/Cart.asmx/AddProduct", $data, $headers));

    //$this->result = $client->getBody();

    //var_dump($client->getHeaders());
    }
  }
}
?>